package io.renren.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 处理时间的工具
 */
public class DateTimeUtil {
    /**
     * 得到时间段
     * @return
     */
    public  static String  TimeQuantum(Date begainTime, Date endTime){
        Integer bengainTime_hour=begainTime.getHours();
        Integer bengainTime_min=begainTime.getMinutes();
         Integer timeQuantum_begain=bengainTime_hour*2+(bengainTime_min>30?1:0);
        Integer endTime_hour=endTime.getHours();
        Integer endTime_min=endTime.getMinutes();
        Integer timeQuantum_end=endTime_hour*2+(endTime_min>30?1:0);
        StringBuffer buffer=new StringBuffer("");
        for(Integer i=timeQuantum_begain;i<timeQuantum_end;i++){
            if(i!=timeQuantum_begain){
                buffer=  buffer.append("|"+i);

            }else{
                buffer=  buffer.append(i);
            }
        }return  buffer.toString();

    }


    public static Integer getTimeQuantum(Date begainTime){
        Integer bengainTime_hour=begainTime.getHours();
        Integer bengainTime_min=begainTime.getMinutes();
        Integer timeQuantum_begain=bengainTime_hour*2+(bengainTime_min>30?1:0);
        return  timeQuantum_begain;
    }

    /**
     * 连个时间 进行比较 前一个时间大的话 返回true
     * @return
     */
    public static boolean compareTime( Date endTime, Date begainTime){
         if(endTime.getTime()>begainTime.getTime()){
          return  true;
         } return  false;
    }

    /***
     * 拿到当前的是时间
     * @return
     */
    public static String date(Date begainTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String datef = sdf.format(begainTime);
        return  datef;
    }

    public static String dateTime(Date begainTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String datef = sdf.format(begainTime);
        return  datef;
    }

    public static String dateTime1(Date begainTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String datef = sdf.format(begainTime);
        return  datef;
    }

}
